var htmlCodes = [
    '<div id="printProduct" v-cloak>',
    '    <el-dialog title="打印生产单" :visible.sync="dialogVisible">',
    '        <!--startprint-->',
    '        <div id="forPrint" style="width: 210mm">',
    '        <table width="100%" border="0" cellpadding="0" cellspacing="0">',
    '            <tbody>',
    '            <tr>',
    '                <td width="33%"> </td>',
    '                <td  align="center">',
    '                    <p style="font-size: 3em;margin: 0 0 0;">生产单</p>',
    '                </td>',
    '                <td width="33%" align="right"></td>',
    '            </tr>',
    '            </tbody>',
    '        </table>',
    '        <table width="100%" border="0" cellpadding="0" cellspacing="0">',
    '            <tbody>',
    '            <tr>',
    '                <td width="40%">&nbsp;&nbsp;&nbsp;&nbsp;订单号：{{erpOrder.orderNo}}</td>',
    '                <td width="30%">接单时间：{{erpOrder.createTime}}</td>',
    '                <td>项目名称：{{erpOrder.projectName}}</td>',
    '            </tr>',
    '            <tr>',
    '                <td width="40%">&nbsp;&nbsp;&nbsp;&nbsp;客户名称：{{erpOrder.memberName}}</td>',
    '                <td width="30%">联系人：{{erpOrder.shipName}}</td>',
    '                <td>联系电话：',
    '                    <span v-if="erpOrder.shipMobile!=null">{{erpOrder.shipMobile}}</span>',
    '                    <span v-else>{{erpOrder.shipTel}}</span>',
    '                </td>',
    '            </tr>',
    '            </tbody>',
    '        </table>',
    '        <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">',
    '            <thead>',
    '            <tr >',
    '                <td width="20%" height="10px" align="center">产品名称</td>',
    '                <td align="center" colspan=3>规格/尺寸/材质/工艺</td>',
    '                <td width="10%" align="center">数量</td>',
    '                <td width="10%" align="center">份数</td>',
    '                <td width="10%" align="center">备注</td>',
    '            </tr>',
    '            </thead>',
    '            <tbody>',
    '            <tr v-for="(item,index) in orderItemDetailData" :key="index">',
    '                <td align="center" height="10px">{{item.name}}</td>',
    '                <td align="center" colspan=3>{{item.addon}}</td>',
    '                <td align="center">{{item.nums}}</td>',
    '                <td align="center">{{item.copy}}</td>',
    '                <td align="center">{{item.itemRemark}}</td>',
    '            </tr>',
    '            </tbody>',
    '        </table>',
    '        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">',
    '            <tbody>',
    '            <tr>',
    '                <td width="60%" colspan=2>制单人:</td>',
    '                <td width="20%">打印人:</td>',
    '                <td></td>',
    '            </tr>',
    '            </tbody>',
    '        </table>',
    '        </div>',
    '        <!--endprint-->',
    '        <span slot="footer" class="dialog-footer">',
    '            <el-button @click="dialogVisible = false" size="small">取 消</el-button>',
    '            <el-button type="primary" @click="doPrint" size="small">打 印</el-button>',
    '        </span>',
    '    </el-dialog>',
    '</div>'
].join("");

Vue.component('zy-print-production', {
    template: htmlCodes,
    props: {
        orderNo: '',
    },
    data: function () {
        return {
            erpOrder: {},
            orderItemDetailData: {},
            dialogVisible: false,
        }
    },
    methods: {
        doPrint: function () {
            var printData = document.getElementById("forPrint").innerHTML; // 只打印 forPrint 这个div中的内容。
            window.document.body.innerHTML = printData;   //把 html 里的数据 复制给 body 的 html 数据 ，相当于重置了整个页面的 内容
            window.print()
            window.location.reload();
            //将原有页面还原到页面
            // document.getElementById("forPrint").innerHTML = printData;
        },
        getOrderData: function (orderNo) {
            var self=this
            $.get(baseURL + "order/erporder/info/" + orderNo, function (r) {
                if (r.code == 0) {
                    self.erpOrder = r.erpOrder;
                    self.orderItemDetailData = r.orderItemDetailData;
                    //处理数据
                    if (self.orderItemDetailData.length > 0) {
                        for (var i = 0; i < self.orderItemDetailData.length; i++) {
                            var item = self.orderItemDetailData[i];
                            var addon = item.addon;
                            if (addon) {
                                //判断是否为json
                                try {
                                    var addonArr = JSON.parse(addon);
                                    //循环取出 参数
                                    var addonStr = '';
                                    for (var j = 0; j < addonArr.length; j++) {
                                        var str = '';
                                        var addon = addonArr[j];
                                        var craftParam = addon.craftParam;
                                        var partsName = addon.partsName;
                                        if (partsName) {
                                            str += partsName + ":";
                                        }
                                        if (!$.isEmptyObject(craftParam)) {
                                            for (key in craftParam) {
                                                str += craftParam[key] + ",";
                                            }
                                            //str+=JSON.stringify(craftParam).replace('}','').replace('{','').replace(/\"/g,'');
                                        }
                                        var basicParam = addon.basicParam;
                                        if (!$.isEmptyObject(basicParam)) {
                                            for (key in basicParam) {
                                                if (key != '是否自来纸') {
                                                    str += basicParam[key] + ",";
                                                }
                                            }
                                            //str+=JSON.stringify(basicParam).replace('}','').replace('{','').replace(/\"/g,'');
                                        }

                                        addonStr += str;
                                    }
                                    if (addonStr) {
                                        self.orderItemDetailData[i].addon = addonStr;
                                    }

                                } catch (err) {
                                    //不做处理
                                }
                            }
                            // cutModel 转换
                            if (!$.isEmptyObject(item.cutModel)) {
                                item.cutModelObj = JSON.parse(item.cutModel);
                            }
                        }
                    }
                    self.dialogVisible = true;
                } else {
                    alert(r.msg);
                }

            })
        },
    }


})

